

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my-blog/img/fluid.png">
  <link rel="icon" href="/my-blog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="木舟">
  <meta name="keywords" content="python Vue Test 测试开发 自动化测试">
  
    <meta name="description" content="前言Dom操作对应的是页面操作，通过Dom，可以操作页面元素的显示、行为逻辑。 Bom（全称 Brower Object Model），对应的是浏览器。 同样，Bom Api是浏览器提供给Javascript，所以不同的浏览器厂商不同的版本，会有一些兼容性的问题。 不过，按照现代浏览器的发展，这些兼容性的问题几乎不需要考虑。    对象 描述    window 是浏览器中代表了当前网页创建的超全">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaScript-Bom操作">
<meta property="og:url" content="https://walker_kwu.gitee.io/my-blog/2022/10/30/notes/js/bom/">
<meta property="og:site_name" content="My Blog">
<meta property="og:description" content="前言Dom操作对应的是页面操作，通过Dom，可以操作页面元素的显示、行为逻辑。 Bom（全称 Brower Object Model），对应的是浏览器。 同样，Bom Api是浏览器提供给Javascript，所以不同的浏览器厂商不同的版本，会有一些兼容性的问题。 不过，按照现代浏览器的发展，这些兼容性的问题几乎不需要考虑。    对象 描述    window 是浏览器中代表了当前网页创建的超全">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-10-30T08:20:22.000Z">
<meta property="article:modified_time" content="2023-05-23T10:37:53.253Z">
<meta property="article:author" content="木舟">
<meta property="article:tag" content="测试开发">
<meta property="article:tag" content="测试平台">
<meta property="article:tag" content="javascript">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>JavaScript-Bom操作 - My Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/my-blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/my-blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/my-blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"walker_kwu.gitee.io","root":"/my-blog/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/my-blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/my-blog/js/utils.js" ></script>
  <script  src="/my-blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/my-blog/">
      <strong>木舟</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/my-blog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="JavaScript-Bom操作"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        木舟
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-10-30 16:20" pubdate>
          2022年10月30日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          3.1k 字
        
      </span>
    

    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">JavaScript-Bom操作</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2023年5月23日 晚上
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>Dom操作对应的是页面操作，通过Dom，可以操作页面元素的显示、行为逻辑。</p>
<p>Bom（全称 Brower Object Model），对应的是浏览器。</p>
<p>同样，Bom Api是浏览器提供给Javascript，所以不同的浏览器厂商不同的版本，会有一些兼容性的问题。</p>
<p>不过，按照现代浏览器的发展，这些兼容性的问题几乎不需要考虑。</p>
<table>
<thead>
<tr>
<th>对象</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>window</td>
<td>是浏览器中代表了当前网页创建的超全局对象，是js操作浏览器中的最高顶级对象，一个浏览器下可以有多个window对象。</td>
</tr>
<tr>
<td>location</td>
<td>地址栏对象</td>
</tr>
<tr>
<td>history</td>
<td>历史记录对象</td>
</tr>
<tr>
<td>screen</td>
<td>屏幕对象[少用]</td>
</tr>
<tr>
<td>document</td>
<td>文档对象[只有少部分是属于BOM操作的，大部分是属于DOM操作]</td>
</tr>
</tbody></table>
<h1 id="window"><a href="#window" class="headerlink" title="window"></a>window</h1><p>window是js提供的全局对象，针对js提供给开发者使用的一切操作，都是属于window对象直接提供或间接提供的，比如之前我们常见到的定时器，就是window提供的内置函数。</p>
<p><strong>常用的属性方法</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * window</span><br><span class="hljs-comment"> *    代表整个浏览器的窗口，同时也是网页中的全局对象</span><br><span class="hljs-comment"> *       setInterval()	按照指定的周期（以毫秒计）来调用函数或计算表达式。</span><br><span class="hljs-comment"> *       setTimeout()	在指定的毫秒数后调用函数或计算表达式。</span><br><span class="hljs-comment"> *       clearInterval()	取消由 setInterval() 设置的 timeout。</span><br><span class="hljs-comment"> *       clearTimeout()	取消由 setTimeout() 方法设置的 timeout。</span><br><span class="hljs-comment"> *       alert()	显示带有一段消息和一个确认按钮的警告框。</span><br><span class="hljs-comment"> *       close()	关闭浏览器窗口。</span><br><span class="hljs-comment"> *       confirm()	显示带有一段消息以及确认按钮和取消按钮的对话框。</span><br><span class="hljs-comment"> *       open()	    打开一个新的浏览器窗口或查找一个已命名的窗口。</span><br><span class="hljs-comment"> *       stop()	    停止页面载入。</span><br><span class="hljs-comment"> *       localStorage	在浏览器内存中存储 key/value 对。</span><br><span class="hljs-comment"> *       addEventListener  创建事件监听</span><br><span class="hljs-comment"> *       removeEventListener  移除事件监听</span><br><span class="hljs-comment"> */</span><br></code></pre></td></tr></table></figure>


<h1 id="location"><a href="#location" class="headerlink" title="location"></a>location</h1><p>地址栏管理对象</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>href</td>
<td>当前页面的url地址完整内容</td>
</tr>
<tr>
<td>protocol</td>
<td>当前页面的url地址的协议名称，常见的协议：<code>http</code>，<code>https</code>，<code>file</code> ，<code>ftp</code>，<code>ws</code>，<code>wss</code>。</td>
</tr>
<tr>
<td>host</td>
<td>当前页面的url地址的完整的服务器主机地址或者完整站点域名。格式：主机名+端口</td>
</tr>
<tr>
<td>hostname</td>
<td>当前页面的url地址的服务器主机名或者站点域名</td>
</tr>
<tr>
<td>port</td>
<td>当前页面的url地址的服务器端口</td>
</tr>
<tr>
<td>origin</td>
<td>当前页面的url地址的主机地址，格式：<code>协议+IP+端口</code>或者<code>协议+域名+端口</code></td>
</tr>
<tr>
<td>pathname</td>
<td>当前页面的url地址对应的服务端资源路径</td>
</tr>
<tr>
<td>search</td>
<td>当前页面的url地址的查询字符串，就是<code>?</code>号后面的内容</td>
</tr>
<tr>
<td>hash</td>
<td>返回一个URL的锚部分</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>方法</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>location.assign(url)</td>
<td>页面跳转，切换当前浏览器显示导航地址为指定url地址</td>
</tr>
<tr>
<td>localtion.reload()</td>
<td>页面刷新，相当于手动F5</td>
</tr>
<tr>
<td>replace()</td>
<td>用新的文档替换当前文档，和assign()功能类似，但不会生成历史记录，导致不能使用回退功能</td>
</tr>
</tbody></table>
<h1 id="history"><a href="#history" class="headerlink" title="history"></a>history</h1><p>可以操作前后翻页，且只在本次访问有效</p>
<p><strong>属性和方法</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs js"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * History</span><br><span class="hljs-comment"> *      back()	    加载 history 列表中的前一个 URL,和浏览器的回退按钮一样</span><br><span class="hljs-comment"> *      forward()	加载 history 列表中的下一个 URL,和浏览器的前进按钮一样</span><br><span class="hljs-comment"> *      go()	    跳转到指定页面，正数向前跳，负数向后退，数字跳转到哪个页面</span><br><span class="hljs-comment"> *      length	    返回历史列表中的网址数</span><br><span class="hljs-comment"> */</span><br></code></pre></td></tr></table></figure>

<h1 id="screen"><a href="#screen" class="headerlink" title="screen"></a>screen</h1><table>
<thead>
<tr>
<th>属性</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>availTop</td>
<td>返回屏幕上方边界的第一个像素点（大多数情况下返回 0）</td>
</tr>
<tr>
<td>availLeft</td>
<td>返回屏幕左边边界的第一个像素点（大多数情况下返回 0）</td>
</tr>
<tr>
<td>availHeight</td>
<td>返回屏幕的高度（不包括 Windows 任务栏）</td>
</tr>
<tr>
<td>availWidth</td>
<td>返回屏幕的宽度（不包括 Windows 任务栏）</td>
</tr>
<tr>
<td>colorDepth</td>
<td>返回屏幕的颜色深度（color depth），根据 CSSOM（CSS 对象模型）视图，为兼容起见，该值总为 24。</td>
</tr>
<tr>
<td>height</td>
<td>返回屏幕的完整高度</td>
</tr>
<tr>
<td>pixelDepth</td>
<td>返回屏幕的位深度/色彩深度（bit depth），根据 CSSOM（CSS 对象模型）视图，为兼容起见，该值总为 24</td>
</tr>
<tr>
<td>width</td>
<td>返回屏幕的完整宽度</td>
</tr>
<tr>
<td>orientation</td>
<td>返回当前屏幕的方向</td>
</tr>
</tbody></table>
<h1 id="本地存储"><a href="#本地存储" class="headerlink" title="本地存储"></a>本地存储</h1><p>本地存储是HTML5中由浏览器提供给我们开发者用于保存数据到浏览器中的2个对象。这2个对象的使用方式是一样的，但是存储时间的有效时间不一样。</p>
<p>注意：本地存储的数据都是按<strong>域名/IP:端口</strong>来分开存储的。所以不同域名下的内容互不干扰的，甚至同一个域名不同端口保存数据都是相互隔离的。与cookie类似，但是cookie是属于旧时代的前端技术，已经在web开发中逐步被淘汰了，所以本地存储实际上就是替代cookies保存客户端数据的一种方式。</p>
<table>
<thead>
<tr>
<th>对象</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><strong><code>localStorage</code></strong></td>
<td>永久存储, 只要不是主动删除，则数据都会一直在浏览器中</td>
</tr>
<tr>
<td><strong><code>sessionStorage</code></strong></td>
<td>会话存储, 基于浏览器窗口保存数据，当用户关闭了浏览器页面以后，则数据会被删除掉，或新建窗口无法原窗口数据。</td>
</tr>
</tbody></table>
<p>实际做项目中，我们通常会使用localStorage来存储token</p>
<p>以及会进行一些定制化配置，比如自定义列、自定义筛选、自定义排序等。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-keyword">html</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Title<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="language-css"></span><br><span class="language-css">    *&#123;</span><br><span class="language-css">        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;</span><br><span class="language-css">        <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;</span><br><span class="language-css">    &#125;</span><br><span class="language-css">    <span class="hljs-selector-tag">div</span>&#123;</span><br><span class="language-css">        <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;</span><br><span class="language-css">        <span class="hljs-attribute">height</span>:<span class="hljs-number">200px</span>;</span><br><span class="language-css">        <span class="hljs-attribute">background-color</span>: red;</span><br><span class="language-css">    &#125;</span><br><span class="language-css">    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// 添加数据到本地存储中</span></span><br><span class="language-javascript">    <span class="hljs-variable language_">localStorage</span>.<span class="hljs-title function_">setItem</span>(<span class="hljs-string">&quot;属性名&quot;</span>,<span class="hljs-string">&quot;数据&quot;</span>)</span><br><span class="language-javascript">    <span class="hljs-variable language_">localStorage</span>.属性名=<span class="hljs-string">&quot;数据&quot;</span></span><br><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-variable language_">localStorage</span>.<span class="hljs-title function_">setItem</span>(<span class="hljs-string">&quot;name&quot;</span>,<span class="hljs-string">&quot;root&quot;</span>)</span><br><span class="language-javascript">    <span class="hljs-variable language_">localStorage</span>.<span class="hljs-property">status</span> = <span class="hljs-number">100</span></span><br><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// // 修改本地存储中的数据</span></span><br><span class="language-javascript">    <span class="hljs-comment">// // 本地存储中的属性名是唯一的，所以针对同一个属性名的值进行修改即可</span></span><br><span class="language-javascript">    <span class="hljs-comment">// localStorage.name=&quot;xiaoming&quot;</span></span><br><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// 获取本地存储中的数据</span></span><br><span class="language-javascript">    <span class="hljs-comment">// localStorage.变量名</span></span><br><span class="language-javascript">    <span class="hljs-keyword">var</span> ret = <span class="hljs-variable language_">localStorage</span>.<span class="hljs-title function_">getItem</span>(<span class="hljs-string">&quot;status&quot;</span>)</span><br><span class="language-javascript">    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(ret) <span class="hljs-comment">// 文本格式数据，所以一般复杂的数据保存到本地存储中，都是经过JSON或者base编码处理的</span></span><br><span class="language-javascript"></span><br><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// // 删除本地存储中一个或全部数据</span></span><br><span class="language-javascript">    <span class="hljs-comment">// localStorage.removeItem(&quot;name&quot;)</span></span><br><span class="language-javascript">    <span class="hljs-comment">// // 清空当前域名在本地存储中的所有数据，慎用</span></span><br><span class="language-javascript">    <span class="hljs-comment">// localStorage.clear()</span></span><br><span class="language-javascript"></span><br><span class="language-javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span><br><br></code></pre></td></tr></table></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/my-blog/categories/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/" class="category-chain-item">测试开发</a>
  
  
    <span>></span>
    
  <a href="/my-blog/categories/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/javascript/" class="category-chain-item">javascript</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/">#测试开发</a>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%B9%B3%E5%8F%B0/">#测试平台</a>
      
        <a href="/my-blog/tags/javascript/">#javascript</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>JavaScript-Bom操作</div>
      <div>https://walker_kwu.gitee.io/my-blog/2022/10/30/notes/js/bom/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>木舟</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年10月30日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年5月23日</div>
        </div>
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="NC - 非商业性使用">
                <i class="iconfont icon-nc"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="SA - 相同方式共享">
                <i class="iconfont icon-sa"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my-blog/2022/11/03/notes/js/JQuery/" title="JQuery--老牌王者">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">JQuery--老牌王者</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my-blog/2022/10/29/notes/js/dom/" title="JavaScript Dom操作">
                        <span class="hidden-mobile">JavaScript Dom操作</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <span>By 木舟</span> <i class="iconfont icon-love"></i> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/my-blog/js/events.js" ></script>
<script  src="/my-blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/my-blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/my-blog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/my-blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
